package org.xiaov.codeautocreator.web.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.xiaov.codeautocreator.common.R;
import org.xiaov.codeautocreator.common.request.TableListRequest;
import org.xiaov.codeautocreator.entity.TableEntity;
import org.xiaov.codeautocreator.service.CodeAutoCreatorService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;


/**
 * <p>
 * 描述：
 * </p>
 *
 * @author xiaovcloud
 * @since 2021/9/5 21:12
 */
@RestController
@RequestMapping("/autocode")
@Api(value = "代码生成")
@Validated
public class CodeAutoCreatorController {
    @Resource
    CodeAutoCreatorService codeAutoCreatorService;


    @PostMapping("/list")
    @ApiOperation(value = "列表展示数据库表")
    public R list(@Validated  @RequestBody TableListRequest request) {

        List<TableEntity> tableList = codeAutoCreatorService.queryList(request);
        return R.ok().setData(tableList);
    }

    @PostMapping("/code")
    @ApiOperation(value = "生成代码")
    public R autocode(String tables) {
        boolean result = codeAutoCreatorService.autocode(tables.split(","));
        return R.ok().setData(result);
    }
}
